package wang.unclecat.actcaller;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.DependentLayout;

class RouterSlice extends AbilitySlice {
    private ActCaller.Callback callback;

    public RouterSlice(ActCaller.Callback callback) {
        this.callback = callback;
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        DependentLayout dependentLayout = new DependentLayout(this);
        dependentLayout.setBackground(null);
        super.setUIContent(dependentLayout);
        startAbilityForResult(intent, 0);
    }

    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);

        terminate();
        if (callback != null) {
            if (resultData == null) {
                resultData = new Intent();
            }
            callback.onAbilityResult(resultData);
        }
    }
}
